package com.csp.mingyue.global.controller;

import com.csp.mingyue.global.exception.BusinessException;
import com.csp.mingyue.global.model.MingYueUser;
import com.csp.mingyue.global.service.MingYueUserService;
import com.csp.mingyue.global.util.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/** @author Strive */
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class MingYueUserController {

  private final MingYueUserService mingYueUserService;

  @GetMapping("/{userId}")
  public R<MingYueUser> queryUserById(@PathVariable Long userId) {
    return R.ok(mingYueUserService.queryUserById(userId));
  }

  @GetMapping("/exception/{userId}")
  public R<MingYueUser> queryUserByIdError(@PathVariable Long userId) {

    if (1 == 1) {
      throw new BusinessException(316, "测试业务异常返回");
    }

    return R.ok(mingYueUserService.queryUserById(userId));
  }

}
